package com.zhangql.util;

import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

public class ActivityStack extends Application{
    private List<Activity> activityList = new LinkedList<Activity>();
    
    private static ActivityStack instance;
    
    private ActivityStack(){
    	
    }
    
    public synchronized static ActivityStack getInstance(){
    	if(null==instance){
    		instance = new ActivityStack();
    	}
    	return instance;
    }
    
    //add Activity
    public void addActivity(Activity activity){
    	activityList.add(activity);
    }
    
    public void exit(){
    	try {
			for(Activity act:activityList){
				if(act!=null){
					act.finish();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			System.exit(0);
		}
    }
    
    @Override
    public void onLowMemory(){
    	super.onLowMemory();
    	System.gc();
    	System.out.println("Android GC By Application");
    }
}
